package Junit;

import static org.junit.Assert.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import de.edb.dao.AbstractDataAccessTest;
import de.edb.dao.DaoException;
import de.edb.dao.EventDao;
import de.edb.dao.LocationDao;
import de.edb.model.Artist;
import de.edb.dao.ArtistDao;
import de.edb.model.Event;
import de.edb.model.Location;
import de.edb.dto.EventArtistDTO;
import de.edb.dto.EventLocationArtistDTO;

public class EventJunit extends AbstractDataAccessTest{

	private static final int eid = 15;
	private static final int aid = 49;
	private static final int lid = 12;
	
	private EventDao edao;
	private ArtistDao adao = null;
	private LocationDao ldao = null;
	
	public void setUserService(EventDao edao)
	{
	    this.edao = edao;  
	}
	
	public void setArtistDao(ArtistDao adao) {
		this.adao = adao;
	}
	
	public void setLocationDao(LocationDao ldao) {
		this.ldao = ldao;
	}
	
	
@Test
public void testFindById()
{
	Event event = this.edao.findById(eid);
	assertTrue(event.getId()==eid);
}

@Test
public void testDelete()
{
//	SessionFactory sessionFactory = this.edao.getSessionFactory();
//	Session session = sessionFactory.getCurrentSession();
//	
//	Event event = this.edao.findById(eid);			
//	
//	edao.delete(event);
//	session.flush();
////	assertEquals(0, edao.findByName("JunitTestEvent").size());
//	assertEquals(null, edao.findById(eid));
}


@Test
public void testFindByName() 
{
	Set<EventArtistDTO> eaDTO = this.edao.findByName("Test");  // Parameter needs to be updated with existing values in DB. This applies to all unit tests 
	assertFalse(eaDTO.isEmpty());	
}


@Test
public void testFindByArtist()
{
	Artist artist = this.adao.findById(aid);
	assertTrue(artist.getId()== aid);
	Set<Event> event = this.edao.findByArtist(artist);
	assertFalse(event.isEmpty());	
	assertTrue(event.containsAll(this.edao.findByName("wut wut")));	
}

@Test
public void testFindByLocation()
{
	Location location = ldao.findById(lid);
	Set<Event> event = edao.findByLocation(location);
	assertTrue(event.containsAll(this.edao.findByName("JunitTestLocation")));	
}


@Test
public void testFindAll()
{
	List<Event> event = this.edao.findAll(); 
	assertTrue(event.size() == 4);  // currently 2 active Events in DB. if error -> update parameter
	assertFalse(event.isEmpty());
}

@Test
public void testFindAllDTO()
{
	Set<EventArtistDTO> eaDTO = edao.findAllDTO();
//	assertTrue(eaDTO.size() == 2);  // if error -> update parameter
	assertFalse(eaDTO.isEmpty());
}

@Test
public void testFindFutureDTO()
{
	Set<EventArtistDTO> eaDTO = edao.findFutureDTO();
//	assertTrue(eaDTO.size() == 2);  // if error -> update parameter
	assertFalse(eaDTO.isEmpty());
}

@Test
public void testFindPastDTO()
{
	Set<EventArtistDTO> eaDTO = edao.findPastDTO();
//	assertTrue(eaDTO.size() == 2);  // if error -> update parameter
	assertFalse(eaDTO.isEmpty());
}


@Test
public void testCreateEvent() throws DaoException, ParseException
{
//	
//	edao.createEvent(9, test, "JunitTestEvent", "JunitTest", start, end, 1.0D, "http://www.link.de");
//	assertEquals(1, edao.findByName("JunitTestEvent").size());
}

}
